
import React from 'react';

import styles from './Order.css';
import OrderNav from "../../components/order/OrderNav";
import OrderAddress from "../../components/order/OrderAddress";
import GiftLocationPros from "../../components/GiftLocationPros";
import OrderBody from "../../components/order/OrderBody";
import OrderSuccess from "../../components/order/OrderSuccess";


class Order extends React.Component<GiftLocationPros,any>{

  constructor(props) {
    super(props);
  }


  showBody(bodyName,gift,exchangeNumber,orderNo:string){
    if(bodyName ==1){
      return (<OrderBody/>);
    }else if(bodyName ==2){
      return <OrderAddress gift={gift} exchangeNumber={exchangeNumber}/>;
    }else if(bodyName ==3){
      return <OrderSuccess orderNo={orderNo}/>
    }
  }

  componentWillMount(){
    let username = sessionStorage.getItem("username");
    if(username ==undefined || username ==''){
      window.document.location.href='/point-shopping';
    }
    if(this.props.location.state == undefined){
      window.document.location.href='/point-shopping';
    }
    if(this.props.location.state.gift == undefined){
      window.document.location.href='/point-shopping';
    }
  }

  render() {
    const {gift,exchangeNumber,bodyName,orderNo} = this.props.location.state
    return (
      <div className={[styles.container,styles["container-user"]].join(' ')}>
        <div>
          <div className={[styles.section,styles["section-subnav"]].join(' ')}>
            <div className={styles.section_subnav}>
              <p className={styles.subnav_title}>积分兑换</p>
            </div>
          </div>
          <OrderNav bodyName={bodyName}/>
          {this.showBody(bodyName,gift,exchangeNumber,orderNo)}

        </div>
      </div>
    );
  }
}

export default Order;
